<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;
use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $user_id 
 * @property int $search_nums 
 * @property int $used_search_nums 
 * @property float $balance 
 * @property float $used_balance 
 * @property float $frozen_balance 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class UserAccount extends Model
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user_account';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id',
        'balance',
        'used_balance',
        'frozen_balance'
    ];

    protected $appends=[
        'able_balance'
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'user_id' => 'integer', 'balance' => 'float', 'used_balance' => 'float', 'frozen_balance' => 'float', 'created_at' => 'datetime', 'updated_at' => 'datetime'];


    public function getAbleBalanceAttribute(){
        return sprintf('%.2f',$this->balance-$this->used_balance-$this->frozen_balance);
    }
}